/**
 * @author wangj881
 * @date 2024-11-29 15:02
 */
public class L376_2 {
    public static void main(String[] args) {
//        int[] nums = {0, 0, 0};
//        int[] nums = {1,17,5,10,13,15,10,5,16,8};
        int[] nums = {1,7,4,9,2,5};
        int i = new Solution().wiggleMaxLength(nums);
        System.out.println(i);
    }

    static class Solution {
        public int wiggleMaxLength(int[] nums) {
            if (nums.length < 2) {
                return nums.length;
            }
            int last = 0;
            int next;
            int result = 0;
            for (int i = 1; i < nums.length; i++) {
                next = nums[i] - nums[i - 1];
                if ((next > 0 && last <= 0) || (next < 0 && last >= 0)) {
                    result++;
                    last = next;
                }
            }
            return result + 1;
        }

    }
}
